home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / pdcurs21 / private / _backchr.c < prev    next >
C/C++ Source or Header  |  1993-06-18  |  2KB  |  105 lines

  1. #define    CURSES_LIBRARY    1
  2. #include <curses.h>
  3.  
  4. #ifdef PDCDEBUG
  5. char *rcsid__backchr = "$Header: C:\CURSES\private\RCS\_backchr.c 2.1 1993/06/18 20:23:08 MH Rel MH $";
  6. #endif
  7.  
  8.  
  9.  
  10.  
  11. /*man-start*********************************************************************
  12.  
  13.   PDC_backchar()    - Visually erase character in window
  14.  
  15.   PDCurses Description:
  16.      This is a private PDCurses function
  17.  
  18.      This routine will visually erase a character.  It is called by
  19.      the PDCurses character I/O routines.
  20.  
  21.   PDCurses Return Value:
  22.      This routine will return OK upon success and otherwise ERR will be
  23.      returned.
  24.  
  25.   PDCurses Errors:
  26.      It is an error to pass a NULL WINDOW pointer.
  27.  
  28.   Portability:
  29.      PDCurses    int    PDC_backchar( WINDOW* w, char* ch, int* len );
  30.  
  31. **man-end**********************************************************************/
  32.  
  33. int    PDC_backchar(WINDOW *w, char *ch, int *len)
  34. {
  35.     int    nbs = 0;
  36.     int    x = w->_curx;
  37.     int    ts = w->_tabsize;
  38.     chtype*    s = &w->_y[w->_cury][x - 1];
  39.     char*    p = c_strbeg;
  40.     bool    save_raw_out = _cursvar.raw_out;
  41.  
  42. #ifdef PDCDEBUG
  43.     if (trace_on) PDC_debug("PDC_backchar() - called\n");
  44. #endif
  45.  
  46.     if (w == (WINDOW *)NULL)
  47.         return( ERR );
  48.  
  49.     (*len)--;        /* Now we are zero relative */
  50.     (*len)--;        /* Now we are looking at the previous
  51.                  * character */
  52.     nbs++;
  53.     /*
  54.      * Determine number of characters to erase...
  55.      */
  56.     if ((ch[*len] < ' ') || (*s == 0x7f))    /* ctrl-char has size 2     */
  57.     {
  58.         nbs++;
  59.         (*len)--;
  60.     }
  61.  
  62.     if (ch[*len] == '\t')    /* tabs are very special */
  63.     {
  64.         for (; p < ch; p++)
  65.         {
  66.             if (*p == '\t')
  67.                 x = ((x / ts) + 1) * ts;
  68.             else
  69.             {
  70.                 if ((*p < ' ') || (*p == 0x7f))
  71.                     x += 2;
  72.                 else
  73.                     x++;
  74.             }
  75.             if (x >= w->_maxx)    /* go to next line? */
  76.                 x = 0;
  77.         }
  78.         if (!(w->_curx))
  79.             nbs = w->_maxx - x;
  80.         else
  81.             nbs = w->_curx - x;
  82.     }
  83.     /*
  84.      * Erase the characters and update...
  85.      */
  86.     _cursvar.raw_out = FALSE;  /* ensure backspace handled in xlat mode */
  87.     while (nbs--)
  88.     {
  89.         if (w->_curx > 0)
  90.         {
  91.             waddstr(w, "\b \b");
  92.         }
  93.         else
  94.         if (w->_cury)
  95.         {
  96.             mvwaddch(w, w->_cury - 1, w->_maxx - 1, ' ');
  97.             wmove(w, w->_cury - 1, w->_maxx - 1);
  98.         }
  99.     }
  100.     ch[*len] = '\0';
  101.     _cursvar.raw_out = save_raw_out;
  102.     wrefresh(w);
  103.     return( OK );
  104. }
  105.